﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Xyz.Web.Reservation.Models.BookingModel>" %>

<%@ Import Namespace="Xyz.Web.Reservation.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Seat Selection
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Seat Selection</h2>
    <% using (Html.BeginForm("Seat", "Shoppingcart", FormMethod.Post, new { id = "seatForm", enctype = "multipart/form-data" }))
       { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend>Seat Information</legend>
        <font color="red"><span id="selectError"></span></font>
        <% 
            for (int i = 0; i < Model.Tickets.Count; i++) %>
        <% { %>
        <fieldset>
            <table style="width: 100%; border: 1; border-collapse: collapse">
                <tr align="left">
                    <td><b>
                        <% if (Model.Tickets[i].isDeparture == true)
                           {%>
                        Departure Flight
                        <% }
                           else
                           { %>
                        Return Flight
                        <%} %>
                        </b>
                    </td>
                    <td>
                        <b>
                        Passenger Name
                        </b>
                    </td>
                    <td>
                        <b>
                        Seat Number
                        </b>
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <%: Model.Tickets[i].Flight.FlightCode%>
                    </td>
                    <td valign="top">
                        <%: string.Concat(Model.Tickets[i].Passenger.LastName, " ", Model.Tickets[i].Passenger.FirstName)%>
                    </td>
                    <!--get previousSeat input from last submission %-->
                    <td>
                        <%: Html.DropDownList("SeatCode" + i, new SelectList((List<string>)ViewData["allSeats" + i]), new { style = "width: 100%;" })%>
                    </td>
                </tr>
                <tr>
                    <!--get seatError from last submission %-->
                    <% if (ViewData["seatError"] != null)
                       {
                           if (((List<string>)ViewData["seatError"]).ElementAt(i).Length > 0)
                           {
                    %>
                    <td colspan="3">
                        <font color="red">
                            <%: ((List<string>)ViewData["seatError"]).ElementAt(i)%></font>
                    </td>
                    <%  }
                       } %>
                </tr>
            </table>
        </fieldset>
        <table>
            <tr>
                <td>
                    <font size="+3">
                        <% if (i == (Model.Tickets.Count - 1) || (Model.TripCode == "RoundTrip" && i == (Model.Tickets.Count / 2 - 1)))
                           {
                               if (Model.Tickets[i].isDeparture == true)
                               {%>
                        Departure Flight Seat Map
                        <% }
                  else
                  { %>
                        Return Flight Seat Map
                        <%} %>
                        <br />
                        <% if (Model.Tickets[i].Flight.AircraftId == 1 || Model.Tickets[i].Flight.AircraftId == 0 || Model.Tickets[i].Flight.AircraftId == 2)
                           { %>
                        <asp:Image ID="seatmap" runat="server" ImageUrl="~/Assets/Images/Airflight1.jpg" />
                        <!-- for other aircraft append if else here for the mapping-->
                        <%}
               } %>
                    </font>
                </td>
            </tr>
        </table>
        <% } %>
        &nbsp;<input type="submit" value="   Next   " class="yellow_button" />
        &nbsp;&nbsp;<input type="button" value="   Reset   " onclick="resetForm()" class="yellow_button" />
    </fieldset>
    <br />
    <br />
    <% } %>
    <script type="text/javascript">
        function resetForm() {
            $("#seatForm").find('input:text, input:password, input:file, select').val('');
            $("#seatForm").find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
        }
        
    </script>
</asp:Content>
